//
//  ZDDWelcomeViewController.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/6/26.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit
import SDWebImage

class ZDDWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImageView
        
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        //动画
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
              
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                            
                            NSNotificationCenter.defaultCenter().postNotificationName(SwiftRootVCNoti, object: "welcome")
                })
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    // MARK: - 设置视图
    private func setupUI() {
        // 添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        //添加约束
    headImageView.snp_makeConstraints { (make) -> Void in
        make.size.equalTo(CGSize(width: 90, height: 90))
        make.top.equalTo(view).offset(400)
        make.centerX.equalTo(view)
        }

    messageLabel.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(view)
        make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
    }
    
    //懒加载控件
    private lazy var bgImageView :UIImageView = UIImageView(imageName: "ad_background")
    
    //头像
    private lazy var headImageView:UIImageView = {
        let img = UIImageView(imageName: "avatar_default_big")
        
        img.layer.cornerRadius = 45
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.borderWidth = 3
        img.layer.masksToBounds = true
        
        //设置图片
        img.sd_setImageWithURL(NSURL(string: ZDDUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        
        return img
    }()
    // 欢迎回来
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.text = "欢迎回来"
        lab.font = UIFont.systemFontOfSize(20)
        lab.textColor = UIColor.grayColor()
        // 对其方式
        lab.textAlignment = .Center
        // 透明度
        lab.alpha = 0
        return lab
    }()
}






















